<?php
  class Plugins_Image extends model {
  
  
  
  function getformadd($productid="")
  {
  
  
  
  
  $echo=1;


$str='    <div class="wrpPlg clBg5 clBd2 bdFull image1">
                    <div class="plgArea"></div>
                    <div class="wrpOutAtcPlg">
                        <div class="wrpAtcPlg">
                            <span class="ico icoImgPlg"></span>
                            <div class="spnAtcPlg clTxtW">
                                <span class="fs03">Image</span><br>
                                <span class="rcmSizeAdd fs01">recommended size: 640px x 360px or larger</span>
                            </div>
                        </div>
                    </div>
                    <div class="wrpTl">
                        <div class="btnIco closeTl clBd3 mgBtm10 deleterowbutton" title="Close">
                            <span class="ico icoCloseTl"></span>
                        </div>
                        <div class="addTool">
                            <div class="btnIco addImgTl clBd3 bdBtm uploadbutton" title="Browse">
                                <span class="ico icoAddImgTl"></span>
                                <div class="wrpUlFile" >
                                    
                                </div>
                            </div>
                            <div class="btnIco addCldTl clBd3 bdBtm cloudbutton" title="Cloud">
                                <span class="ico icoAddCldTl"></span>
                            </div>
                            <div class="btnIco addLnkTl clBd3 bdBtm linkbutton" title="Link">
                                <span class="ico icoAddLnkTl"></span>
                            </div>
                            <div class="btnIco btnRmvTl deletebutton" title="Remove">
                                <span class="ico icoRmvTl"></span>
                            </div>
                        </div>
                    </div>
                    <span class="desPlg clTxt3 fs03">Select an image recommend size 640 x 360 px</span>
                    <form class="frmTprPlg" onsubmit="return false;">
                       
                    
                        <input name="detail[]" type="text" class="inpAddCtntNoBd inpTprPlg w616 clTxt2 fs03" placeholder="Type text here to explain this image.">
                        </form>
                 
                </div>';
  
  
  
  $arraydata['form']=addslashes(str_replace(array("\r", "", "\r"), '', $str));
 // $arraydata['js'][]=pluginjsinfo.'/image.js';
  //$arraydata['js'][]=baseinfo.'/js/jquery.Jcrop.min.js';
 // $arraydata['js'][]=baseinfo.'/js/jquery.iuploader-1.0.js';
  
  
      
  
  
  
  return $arraydata;
  
  
  
  
  
  
  
  }
  
  function getformlanding($arraydata)
  {
  
 if($arraydata['simg']['newpath'])
 {
$code  = '<div class="ldIt wrpImgLd clBg4 w640" onclick="openmaingallery('.$arraydata['simgmid'].')">'."";
$code .= '<div class="icoDefLd">'."";
$code .= '<span class="ico icoImgDefLd"></span>'."";
$code .= '<span>Image</span>'."";
$code .= '</div>'."";
$code .= '<div class="wrpImgDesLd">'."";
$code .= '<a href="javascript:void(0)"   class="galleryimage"><img  id="img-'.$arraydata['simgmid'].'" title="'.$arraydata['img']['newpath'].'" width="640" height="360"  alt="'.$arraydata['img']['width'].'|'.$arraydata['img']['height'].'" src="'.$arraydata['simg']['newpath'].'"></a>'."";
$codeset="";
if($arraydata['detail']=="")
{
$codeset='style="display:none"';
}
$code .= '<div class="desImgLd clTxtW" '.$codeset.'>'."";
$code .= '<div  class="ovlLd ovlImgLd w640">'."";
$code .= '<p class="cutTxt">'.$arraydata['detail'].'</p>'."";
$code .= '</div>'."";
$code .= '</div>'."";
$code .= '</div>'."";
$code .= '</div>';
 }

$data['str']=$code;
$data['target']='secondtarget';
  
  return $data; 
  
  
  }
  
  function getplugin($plugreid)
  {
  $sql="select * from tb_plugins_image where plugreid=".$plugreid;
  $arrayplugin=$this->db->db_set_1recordrow($sql);
 
  $arrayplugin['img']= $this->getimagebyimgmid($arrayplugin['imgmid']);
  $arrayplugin['simg']= $this->getimagebyimgmid($arrayplugin['simgmid']);

  
  return $arrayplugin;
  

  
  }
  
  function saveplugin($arraydata,$productid,$plugreid)
  {
  
  
  $arraydata['productid']=$productid;
  $arraydata['plugreid']=$plugreid;
  
  if($arraydata['photomain'])
  {
  $arraydata['imgmid']= $this->savephotobase64($arraydata['photomain']);
  $arraydata['simgmid']=$arraydata['imgmid'];
  unset($arraydata['photomain']);

  }
  else if($arraydata['photolink'])
            {
            $arraydata['imgmid']=$this->savephotolink($arraydata['photolink']);
            $arraydata['simgmid']=$this->savephotolink($arraydata['photolink'],640,360);
            unset($arraydata['photolink']); 
            
            }
    if($arraydata['simgmid'])$arraydata['simgmid']=$this->swicthpathimage($arraydata['simgmid'],$productid);
   if($arraydata['imgmid'])
   {
   
   $arraydata['imgmid']=$this->swicthpathimage($arraydata['imgmid'],$productid);
   
   
   
 if(NameDmconnex=='Canonlife') 
 {   
  $sql=' select other,tb_img.imgmid
FROM
tb_img
where other!="" and other!="false" and other like "%Model%" and tb_img.imgmid='.$arraydata['imgmid'];
          $dataimg=$this->db->db_set_1recordrow($sql);
          
          
          
          $otherdata= json_decode($dataimg['other']);
          $arraydata2['other']=object_to_array($otherdata);
  
 if($dataimg['imgmid'])
 {                            
 $model='';
 if($arraydata2['other']['IFD0']['Model'])
 {
 $model=$arraydata2['other']['IFD0']['Model'];
 $this->savetagrelatedata($model,$productid);
 
 }
 
 /*
  $len='';
 if($arraydata2['other']['EXIF'])
 {
 if($arraydata2['other']['EXIF']['UndefinedTag:0xA434'])
 {
 $len=$arraydata2['other']['EXIF']['UndefinedTag:0xA434'];
 $this->savetagrelatedata($len,$productid);
 }
 
 }
 
 
   $focus='';
 if($arraydata2['other']['EXIF'])
 {
 if($arraydata2['other']['EXIF']['FocalLength'])
 {
 $focus=$arraydata2['other']['EXIF']['FocalLength'];
$link=str_replace('/','-',$focus);
//$focus=eval($focus).'mm';
list($d1,$d2)=explode("/",$focus);
$focus=($d1/$d2).' mm';

$this->savetagrelatedata($focus,$productid);
 
 }
 
 }
 
 
 
 $shutter='';
 if($arraydata2['other']['EXIF'])
 {
 if($arraydata2['other']['EXIF']['ISOSpeedRatings'])
 {
 $shutter='ISO'.$arraydata2['other']['EXIF']['ISOSpeedRatings'];
 $this->savetagrelatedata($shutter,$productid);
 }
 }
 
 $aperture='';
  if($arraydata2['other']['COMPUTED'])
 {
 if($arraydata2['other']['COMPUTED']['ApertureFNumber'])
 {
 $aperture=$arraydata2['other']['COMPUTED']['ApertureFNumber'];
 $this->savetagrelatedata($aperture,$productid);
 }
 }
 
 
  $exposure='';
  if($arraydata2['other']['EXIF'])
 {
 if($arraydata2['other']['EXIF']['ExposureTime'])
 {
 $exposure=$arraydata2['other']['EXIF']['ExposureTime'];
  $this->savetagrelatedata($exposure,$productid);
 }
 }
 */
 }
 }
   
   
   }
  
 
  

  
  
  
  $this->db->db_set($arraydata,'tb_plugins_image');
  
  }
  
  
  }
?>
